<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="../inc.jsp"></jsp:include>


</head>
<body>

	<script type="text/javascript">
		$(function() {
			//进入页面后关闭进度条提示框
			parent.$.messager.progress('close');

		});

		var pre_contract_datagrid;
		$(function() {

			pre_contract_datagrid = $('#pre_contract_datagrid').datagrid({
				url : '${pageContext.request.contextPath}/ContractController/dataGrid?isRelated=已匹配或部分匹配',
				pagination : true,
				fit : true,
				rownumbers : true,
				fitColumns : true,
				border : false,
				idField : 'contractid',
				pageSize : 10,
				pageList : [ 10, 20 ],
				sortName : 'creatDate',
				sortOrder : 'desc',
				checkOnSelect : true,
				selectOnCheck : true,
				nowrap : false,
				columns : [ [{
					field : 'contractid',
					title : '编号',
					width : 10,
					checkbox : true
				},  {
					field : 'po',
					title : '合同编号',
					width : '130px'
				}, {
					field : 'contractName',
					title : '合同名称',
					width : '280px',

				}, {
					field : 'contractMoney',
					title : '合同金额',
					align : 'center',
					width : '60px',
					formatter : function(value, row, index) {

						return (accounting.formatNumber(value));
					}

				}, {
					field : 'billSumMoney',
					title : '回款金额',
					align : 'center',
					width : '60px',
					formatter : function(value, row, index) {

						return (accounting.formatNumber(value));
					}

				}, {
					field : 'kpMoney',
					title : '开票金额',
					align : 'center',
					width : '60px',
					formatter : function(value, row, index) {

						return (accounting.formatNumber(value));
					}

				} ] ]

			});

		});

		function presearchFun() {
			pre_contract_datagrid.datagrid('load', $.serializeObject($('#presearchForm')));
		}
		
		function releatContract(){
			var selRow = pre_contract_datagrid.datagrid("getSelections");//返回选中多行  

			if (selRow.length == 0) {
				parent.$.messager.show({
					title : '提示信息',
					msg : '请至少选择一行数据!',

				});
				return false;
			}
			var contractids = [];
			for (var i = 0; i < selRow.length; i++) {
				//获取自定义table 的中的checkbox值  
				var id = selRow[i].po; //OTRECORDID这个是你要在列表中取的单个id   
				contractids.push(id); //然后把单个id循环放到ids的数组中  
			}
			
			var incomeName = '${incomeName}';
			incomeName = projectName.replace(/\&/g, "%26");
			incomeName = projectName.replace(/\+/g, "%2B");
			
			var url = '${pageContext.request.contextPath}/IncomeController/releatContract?contractids='
				+ contractids + '&incomeName=' + incomeName;
			
			$.ajax({
				url : url,
				type : 'post',
				dataType : 'json',
				success : function(result) {
					if (result.msg) {
						jQuery.messager.alert("操作结果", result.msg);
						$('#pre_contract_datagrid').datagrid('reload');
						$('#pre_contract_datagrid').datagrid('uncheckAll');
					} else {
						jQuery.messager.alert("系统异常，请联系管理员");
					}
				}
			});
			
			
		}
	</script>

	<div id="prereleatcontractlayout" class="easyui-layout"
		data-options="fit : true">
		<div class="easyui-layout" data-options="fit : true">

			<div data-options="region:'north',title:'',border:false"
				style="height: 30px; margin-top: 10px;">
				<form id="presearchForm">
					<tr>
						<th>合同名称:</th>
						<td><input name="contractName" /></td>
						<th>PO:</th>
						<td><input name="po" /></td>
						<td><a onclick="presearchFun();" href="javascript:void(0);"
							class="easyui-linkbutton" iconCls="icon-search"
							data-options="plain:false">搜索</a></td>
							<td><a onclick="releatContract();" href="javascript:void(0);"
							class="easyui-linkbutton" iconCls="icon-add"
							data-options="plain:false">保存</a></td>
					</tr>
				</form>
			</div>
			<div data-options="region:'center'">
				<table id="pre_contract_datagrid" fitColumns="true"></table>
			</div>
		</div>

	</div>
</body>
</html>